import { watcher } from "@feng3d/watcher";
import { TorusKnotGeometry } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class TorusKnotGeometry3D extends BufferGeometry3D
{
    radius = 1;
    tube = 0.4;
    tubularSegments = 64;
    radialSegments = 8;
    p = 2;
    q = 3;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new TorusKnotGeometry(this.radius, this.tube, this.tubularSegments, this.radialSegments, this.p, this.q);
        }

        return this.__geometry;
    }
    declare protected __geometry: TorusKnotGeometry;

    constructor()
    {
        super();
        watcher.watchs(this as TorusKnotGeometry3D, ["radius", "tube", "radialSegments", "tubularSegments", "p", "q"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as TorusKnotGeometry3D, ["radius", "tube", "radialSegments", "tubularSegments", "p", "q"], this._invalidate, this);
    }
}
